package tulingxueyuan117;

import java.lang.reflect.Array;
import java.util.*;

/**
 * Author: Zhang Dongwei
 * Date: 2022/11/6 14:52
 * 冒泡升序排序
 */
public class p32_冒泡排序_912 {
    public static void main(String[] args) {
        int[] arr = {18, 13, 50, 15, 4, 17, 18};
        System.out.println(Arrays.toString(arr));
        int[] res = bubbleSort(arr);
        System.out.println(Arrays.toString(res));
    }
//    快速排序在力扣912会超时
    public static int[] bubbleSort(int[] arr) {
        for(int i=0; i<arr.length-1; i++){
            for(int j=0; j<arr.length-1-i; j++){
                if(arr[j+1]<arr[j]){
                    int temp = arr[j+1];
                    arr[j+1] = arr[j];
                    arr[j] = temp;
                }
            }
            System.out.println(Arrays.toString(arr));
        }
        return arr;
    }

}
